package es.uab.sound.dao;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;

import es.uab.sound.utils.Logger;

public class UsersDao extends BaseDao implements Serializable {

	private static final long serialVersionUID = 1L;
	private static final String TAG_SUCCESS = "success";

	public boolean loadByUsername(String username, String pass) {
		List<NameValuePair> params = new LinkedList<NameValuePair>();
		params.add(new BasicNameValuePair("username", username));
		params.add(new BasicNameValuePair("pass", pass));
		JSONObject json = makeHttpRequest("access.php", METHOD_POST, params);
		Logger.debug(this, json.toString());
		try {
			int success = json.getInt(TAG_SUCCESS);
			return (success == 1);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return false;
	}
}
